const Koa = require('koa')
const co = require('co')
const render = require('koa-ejs')
const app = new Koa()
const mongoose = require('mongoose')
const routes = require('./routes').default
const bodyParser = require('koa-bodyparser')
const morgan = require('koa-morgan')

mongoose.connect('mongodb://localhost/test')

app.use(morgan('combined'))
app.use(bodyParser())

render(app, {
  root: './views',
  viewExt: 'ejs',
  layout: false
})
app.context.render = co.wrap(app.context.render)

routes.forEach((r) => app.use(r))

const port = 8088
app.listen(port, () => {
  console.log('Server listening at ' + port)
})
